 local playerName = UnitName("player");
 local GTT = GameTooltip;											 

sheppard_UpdateInterval = 1; -- For OnUpdate function
break_timer = -1;              -- Break Timer variable
break_timer_counter = 0;
break_timer_milli = 60;
break_timer_test = 60;
seconds = 0;
TimeSinceLastUpdate = 0;

-- TEXT UI COMMAND LIST
SLASH_sheppard1 = "/sheppard"
function SlashCmdList.sheppard(msg, editbox)

 if (msg == "test") then  -- Eventually should be on a button in the admin UI
	DEFAULT_CHAT_FRAME:AddMessage("Message reads: Testing", 3.1, 0.9, 0.1);
	-------------
 end
 
end


guild = {
	Daemios = {
		info = {
			name = "Daemios", rating = 900	}	
		},
	Darys = {
		info = {
			name = "Darys", rating = 900	}
			}	
} 

-- HOOK: OnTooltipSetUnit
GTT:HookScript("OnTooltipSetUnit",function(self,...)
	-- Get the unit
	local _, unit = self:GetUnit();
	if (not unit) then
		local mFocus = GetMouseFocus();
		if (mFocus) and (mFocus.unit) then
			unit = mFocus.unit;
		end
	end
	-- Get and display rating, and rank
	if (UnitIsPlayer(unit)) then
		local guildName, guildRank = GetGuildInfo(unit);
		
		if ((guildName) and (guildName ~= GetGuildInfo("player"))) then
			self:AddDoubleLine("Rank: [" .. guildRank .. "]");
		end
		if (guildName == GetGuildInfo("player")) then                 -- Checks for own guild
			self:AddDoubleLine("Rank: [" .. guildRank .. "]");
			self:AddDoubleLine("Rating: [" .. guild.Darys.info.rating .. "]");
			--play = Player:new(UnitName("mouseover"), getRole(unit), getRating(unit))   -- Creates new Player object
			--self:AddDoubleLine("Role:", play.role);                   -- Adds role to tooltip dynamically
		end
		
	end
end);




function updateFunc_time(self, elapsed)
	TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed;
	
	
	while (TimeSinceLastUpdate > sheppard_UpdateInterval) do
		hour, minute = GetGameTime();
		
		if (minute == minute2) then
			seconds = seconds + 1
		elseif (minute ~= minute2) then
			seconds = 0
		end
		
	--[[
	break_timer_counter = break_timer_counter + 1;
	break_timer_milli = break_timer_milli - 1.0;
	
	if (break_timer_milli <= 0) then
		break_timer_milli = 60.0;
	end
	
	if (break_timer_counter == 100) then
		break_timer = break_timer - 1.0;
		break_timer_counter = 0;
		break_timer_test = bit.mod(break_timer, 60.0);
	end
	]]
		--DEFAULT_CHAT_FRAME:AddMessage(hour .. ":" .. minute .. ":" .. seconds, 3.1, 0.9, 0.1);
		minute2 = minute;
		TimeSinceLastUpdate = TimeSinceLastUpdate - sheppard_UpdateInterval;
	end
end
local upd = CreateFrame("Frame")
upd:SetScript("OnUpdate", updateFunc_time);

waitlist = {};
waitlist2 = {};

local frame = CreateFrame("FRAME", "sheppard_Event");
frame:RegisterEvent("CHAT_MSG_ADDON");
frame:RegisterEvent("RAID_ROSTER_UPDATE");
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("CHAT_MSG_WHISPER")
local function eventHandler(self, event, ...)

	local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 = ...;
	
	--[[if (event == "CHAT_MSG_WHISPER") then
		local tbl = {}
		for v in string.gmatch(arg1, "[^ ]+") do
			tinsert(tbl, v)
		end

		if (tbl[1] == "wl") then
			if (tbl[2] == "print") then
				if (tbl[3] == "index") then
					--print(waitlist[tbl[4]]--[[ ) ]]
				--[[else
					
					local table_size = table.getn(waitlist2)
					
					j = 1;
					for i = table_size, 1, -1 do
						waitlist[j] = waitlist2[i];
						print(waitlist2[i]);
						j = j + 1;
					end
					
					waitlist_table = table.concat(waitlist, ", ")
					SendChatMessage(" " .. waitlist_table .. " ", "WHISPER", "ORCISH" , arg2);
				end
			elseif (tbl[2] == "add") then
				tbl[3] = string.gsub(tbl[3], "%a", string.upper, 1) --format to first char upper
				local duplicate = false
				for i, v in ipairs(waitlist2) do --check for duplicate
					print(v)
					if (tbl[3] == v) then
						SendChatMessage(tbl[3] .. " is already on the waitlist.", "WHISPER", "ORCISH" , arg2)
						duplicate = true
					end
				end
				
				if (duplicate == false) then
					table.insert(waitlist2, 1, tbl[3])
					SendChatMessage("Added to waitlist: " .. tbl[3], "WHISPER", "ORCISH" , arg2);
				end
				duplicate = false
			end
		end

	end
	]]
	
	if (event == "PLAYER_LOGIN") then
		DEFAULT_CHAT_FRAME:AddMessage("Bahhhhh: WhyHelloThar ".. UnitName("Player"))
	end
	--Subchannel Reader for testing
	if (event == "CHAT_MSG_ADDON") and (arg1 == "sheppard_test") then
		DEFAULT_CHAT_FRAME:AddMessage("Just found a subchannel message. Channel identified as " .. arg1 .. ".", 3.1, 0.9, 0.1);
		DEFAULT_CHAT_FRAME:AddMessage("Message reads: "..arg2..".", 3.1, 0.9, 0.1);
    end
	
	--Subchannel Reader for breaks
	if (event == "CHAT_MSG_ADDON") and (arg1 == "sheppard_break") then
		break_timer = breakIn(arg2);  --Recieves the addon message with the "sheppard_break" tag and converts the string it passes to a variable.
	end                 --This will allow us to send break times over the subchannels with the admin enabled versions of the addons.
	
end
frame:SetScript("OnEvent", eventHandler);
